<?php
require_once 'Database.php';
$db=new DB();
$imagearr = $db->takeGallery();
$arr=array();
?>
<div id="content">
    <div class="gallery">
      <ul>
	      <?php 
            $n=count($imagearr);
    	       for ($i=0;$i<$n;$i++){
    	       	if (!strcmp($imagearr[$i]->getImgToHeader(),"1")){
    	       		echo "<li><a href='#'><img alt='".$imagearr[$i]->getName()."' src='images/gallery/".$imagearr[$i]->getName()."' width='132' height='82' /></a></li>";	      		
    	       		
    	       	} else {
    	       		array_push($arr, $imagearr[$i]);
    	       	}
    	       		
    	       }
    	      $imagearr= $arr;

            if (count($imagearr) % 10 !=0 ) {
               $n = count($imagearr)/10 +1;
            } else {
              $n = count($imagearr)/10;
            }
    	      
            if (intval($_GET['page_number'])<1) {
                 $_GET['page_number'] = $n;
              } elseif (intval($_GET['page_number'])> $n) {
              $_GET['page_number'] =1;    
              } 
            $start = (intval($_GET['page_number'])-1)*10;
            $stop = $start+10;
        ?>

      </ul>
    </div>
    <input type="hidden" name="page_number" id="page_number" value="<?php echo intval($_GET['page_number']);?>" />
    <div class="container">
      <div class="aside maxheight">
        <!-- box begin -->
        <div class="box maxheight">
          <div class="inner">
            <center><h3>
            <?php 
            if (intval($_GET['page_number'])>1)
           		echo '<a href="?page=MKgallery&article=Галерия&page_number='.(intval($_GET['page_number'])-1).'"><img src="images/left_arrow.png">';
            for ($i=1;$i<$n;$i++){
            	echo "<a href='?page=MKgallery&article=Галерия&page_number=$i'> $i</a> ";
            }
            if (intval($_GET['page_number'])<$n-1)
           		echo '<a href="?page=MKgallery&article=Галерия&page_number='.(intval($_GET['page_number'])+1).'"><img src="images/right_arrow.png">';
            ?>
            </h3>
            </center>
            <div class="gallery-images">
              <ul>
	              <?php 
                    $n=count($imagearr);
                    if ($stop>$n) {
                      $stop=$n;
                    } 
                        
      			       	for ($i=$start;$i<$stop;$i++){
      				       	if (strcmp($imagearr[$i]->getImgToHeader(),"1"))
                        echo "<li><a  href=\"javascript:changeGalleryImage('curr','img_$i')\"><img  id='img_$i' alt='$i' src='images/gallery/".$imagearr[$i]->getName()."' width='81' height='58' /></a></li>";
      				       		
      				     }
      			      
      			      ?>
              </ul>
            </div>
          </div>
        </div>
        <!-- box end -->
      </div>
      <div class="content">
        <div class="indent">
          <div class="gallery-main png">
            <div class="inner"> <a name="#image"><img  src="images/gallery/<?php if (isset($_GET['prev'])) {
                                                                                            echo $imagearr[$stop-1]->getName().'"';
                                                                                            echo " alt='".($stop-1)."'";
                                                                                  } else {
                                                                                            echo $imagearr[$start]->getName().'"';
                                                                                            echo " alt='".($start)."'";
                                                                                   }	?>  width="583" height="408" id="image"/></a>
              <div class="prev"><a  href="javascript:changeGalleryImage('prev')"><img  src="images/prev.png" class="png"   id="prevImage"/></a></div>
              <div class="next"><a  href="javascript:changeGalleryImage('next')"><img  src="images/next.png" class="png"   id="nextImage"/> </a></div>
            </div>
          </div>
        </div>
      </div>
      <div class="clear"></div>
    </div>
  </div>